<template>
  <div>
    <!-- 全局定义 -->
    <Dialog
      ref="definePopup"
      dialogCls="mydlgg"
      headerCls="mydlgg-head"
      footerCls="mydlgg-foot"
      :dialogStyle="{ width: '650px' }"
      :modal="true"
      borderType="thin"
      @close="close"
    >
      <div slot="header">
        <span class="headerIcon newlyAdded"></span>
        <span class="titleStyle">全局定义</span>
      </div>

      <div class="insidePadding" style="min-height: 100px;padding-top: 20px;">
        <!-- 这个div必须保留 -->
        <!-- <Tabs
          ref="tabs"
          style="height:200px;"
          :plain="true"
          headerHeight="30px"
          @tabSelect="tabTitle = $event.title"
        >
          <TabPanel
            :title="'规律班次排班'"
            style="border: 1px solid #b8b7bc;border-top: 0;"
          >
            <div class="clearfix" style="padding:10px;">

            </div>
          </TabPanel>
          <TabPanel
            :title="'普通班次排班'"
            style="border: 1px solid #b8b7bc;border-top: 0;"
          >
            <div style="padding:10px;">
              222
            </div>
          </TabPanel>

        </Tabs> -->

        <div class="fleft" style="text-align: right; padding-right: 20px;">
          <Label>法定年假清零时间</Label>
          <DateBox
            format="MM-dd"
            v-model="fdYearHolidayClear"
            :editable="false"
          />
        </div>

        <div class="fleft" style="text-align: right; padding-right: 20px;">
          <Label>福利年假清零时间</Label>
          <DateBox
            format="MM-dd"
            v-model="flYearHolidayClear"
            :editable="false"
          />
        </div>
      </div>

      <div slot="footer" style="border:none">
        <div class="footerDiv">
          <!-- footer、footerDiv这两个div必须保留 -->
          <LinkButton @click="submitDefinePopup" class="saveBtn"
            >保存</LinkButton
          >
          <LinkButton @click="closeDefinePopup" class="cancelBtn"
            >返回</LinkButton
          >
        </div>
      </div>
    </Dialog>
  </div>
</template>

<script>
import moment from "moment";
import cfg from "@/config/config";
import userVacation from "@/api/personnelFile/userVacation";
import dateUtil from "@/utils/dateUtils";
import reqwest from "reqwest";
import sys from "@/api/sys";

export default {
  props: {},
  components: {},
  name: "",
  data() {
    return {
      // 下拉框样式
      panelStyle: {
        height: "auto",
        maxHeight: "140px",
        borderWidth: "1px",
        borderColor: "#ccc",
        borderStyle: "solid"
      },
      fdYearHolidayClear: new Date(),
      flYearHolidayClear: new Date()
    };
  },
  mounted() {
    userVacation.getfdflNjClearDate().then(res => {
      if (res.code == 200) {
        // console.log( res.result);
        if (res.result.fdNjClearDate != "") {
          this.fdYearHolidayClear = new Date(res.result.fdNjClearDate);
        }
        if (res.result.flNjClearDate != "") {
          this.flYearHolidayClear = new Date(res.result.flNjClearDate);
        }
      } else {
        this.$messager.alert({
          title: "出现异常",
          icon: "error",
          msg: res.message
        });
      }
    });
  },
  computed: {},
  methods: {
    close() {
      this.$refs.definePopup.close();
    },
    open() {
      this.$refs.definePopup.open();
    },
    // 保存全局定义
    async submitDefinePopup() {
      let fdYearHolidayClearDate = moment(this.fdYearHolidayClear).format(
        "YYYY-MM-DD"
      );
      let flYearHolidayClearDate = moment(this.flYearHolidayClear).format(
        "YYYY-MM-DD"
      );
      if (
        fdYearHolidayClearDate == "" ||
        fdYearHolidayClearDate == "Invalid date" ||
        fdYearHolidayClearDate == null
      ) {
        this.$messager.alert({
          title: "操作提示",
          icon: "warning",
          msg: "请选择法定年假清零时间!"
        });
        return;
      }
      if (
        flYearHolidayClearDate == "" ||
        flYearHolidayClearDate == "Invalid date" ||
        fdYearHolidayClearDate == null
      ) {
        this.$messager.alert({
          title: "操作提示",
          icon: "warning",
          msg: "请选择福利年假清零时间!"
        });
        return;
      }
      // console.log(fdYearHolidayClearDate);
      // console.log(flYearHolidayClearDate);
      this.$loading("正在保存...");
      let param = {
        fdNjClearDate: fdYearHolidayClearDate,
        flNjClearDate: flYearHolidayClearDate
      };
      let resu = await userVacation.updatefdflNjClearDate(param);
      if (resu.success) {
        this.close();
        this.$messager.alert({
          title: "操作提示",
          icon: "success",
          msg: "保存成功!"
        });
      } else {
        this.$messager.alert({
          title: "操作提示",
          icon: "error",
          msg: resu.message
        });
      }
      this.$loading.close();
    },
    // 关闭弹窗
    closeDefinePopup() {
      this.close();
    }
  }
};
</script>

<style scoped>
.specialStyle {
  float: left;
  width: 33%;
  margin-bottom: 5px;
  text-align: right;
  padding-right: 10px;
}
</style>
